<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">添加食品类别</small>
      </a>
      <a href="javascript:;" class="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
    </header>
    <main>
      <div class="formcontent">
        <ul>
          <li>
            <span> <em>*</em>序号</span>
            <div class="froms">
              <input v-model="formName.sort" id="sort" name="sort" v-validate="'required|numeric'" :class="{'is-danger': errors.has('sort')}">
            </div>
          </li>
          <li>
            <span>名称</span>
            <div class="froms">
              <input v-model="formName.name">
            </div>
          </li>
        </ul>
      </div>
    </main>
  </div>
</template>

<script>
  import {
    DemandTypeAdd
  } from '../../../api/api'
  export default {
    name: 'DemandTypeAdd',
    data() {
      return {
        formName: {
          sort: '',
          name: '',
        }
      };
    },
    methods: {
      submitForm: function() {
        this.$validator.validateAll().then((result) => {
          if (result) {
            let varQueryData = {
              Unid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid
            }
            let data = {
              Sort: this.formName.sort,
              Name: this.formName.name,
              Enterprise: varQueryData,
            }
            let dataoption = {
              params: {
                Data: JSON.stringify(data),
                UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
              }
            }
            //调取接口
            DemandTypeAdd(dataoption).then((res) => {
              if (res.success === true) {
                this.$message.success('保存成功');
                this.$router.go(-1);
              } else {
                this.$message.error(res.msg);
                debugger
              }
            }).catch(function() {
              this.$message.error('网络异常。');
            })
          } else {
            this.$message.error('带*号为必填项，请确认填写格式正确');
          }
        })
  
  
      },
      created() {
  
      },
    }
  }
</script>

<style lang="scss">
  
</style>
